//创建路由对象
import {
  createRouter,
  createWebHashHistory,
} from 'vue-router'
import Error from '../Error.vue'
import Home from '../Home.vue'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [{
      name: 'home',
      path: '/home',
      component:Home
  }, {
      name: 'error',
      path: '/error',
      component:Error
      }
  ]
})

router.beforeEach(to => {
  let user = sessionStorage.getItem('user')
  if (to.path == '/home') {
      if (user) {
      if (JSON.parse(user).acc != "admin" || JSON.parse(user).pwd != "admin") return {path:'/error'};
      else return true
  } else if(to.path=='/') {
      return true
  } 
  }else return true

  

})




export default router
